import bean.Auditer;
import bean.Employee;
import bean.Recruter;
import bean.Victorer;
import bean.enm.AnimalEnum;
import bean.enm.Method;
import bean.impl.AuditOr;
import bean.impl.Coder;
import bean.impl.RecrutOr;
import bean.impl.VictorOr;
import inter.ICaculate;
import inter.impl.CaculateImpl;
import org.junit.Test;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @program: designModel
 * @description: 策略客户端
 * @author: liuxincheng
 * @create: 2019-04-09 09:34
 */
public class StrategyClient {

    @Test
    public void test1(){
        Employee coder = new Coder();
        coder.startWork();
    }

    @Test
    public void test2(){
        Auditer auditer = new AuditOr();
        auditer.audit();
    }


    @Test
    public void test3(){
        Recruter recruter = new RecrutOr();
        recruter.recruting();
    }

    @Test
    public void victor(){
        Victorer victorer = new VictorOr();
        victorer.service();
    }

    @Test
    public void testCal(){
        ICaculate<Integer> caculate = new CaculateImpl<Integer>();
        ICaculate<String> caculate2 = new CaculateImpl<String>();
        System.out.println(caculate.getResult(3,8));
        System.out.println(caculate2.getResult("welcome","china"));
    }

    @Test
    public void testConvert(){
        int a=3,b=4;
        a+=b;
        b=a-b;
        a-=b;
        System.out.println(a+"    "+b);
    }

    @Test
    public void testEmum(){
        String parm1= Method.Get.getValue();
        System.out.println(parm1);

        String foods = AnimalEnum.CAT.eat("fish");
        System.out.println(foods);
    }

    @Test
    public void mesiCache(){
        int a=1;
        int b=2;
        AtomicInteger x = new AtomicInteger();
        AtomicInteger y = new AtomicInteger();
        a=b=0;

        int finalB = b;
        Thread threadA = new Thread(() -> {
            x.set(finalB);
        });

        int finalA = a;
        Thread threadB = new Thread(() -> {
            y.set(finalA);
        });

        threadA.start();
        threadB.start();

        System.out.println(x+"        "+y);
        System.out.printf("%s\n",x==y);
        System.out.printf("%s\n%s",x,y);
    }

    @Test
    public void memoryAddress(){
        Integer a = 128, b = 128, c = 127, d = 127;
        java.lang.String str1 = new java.lang.String("abc");
        java.lang.String str2 = new java.lang.String("abc");
        System.out.println(a == b);
        System.out.println(c == d);
        System.out.println(c.equals(d));
        System.out.println(str1==str2);
        System.out.println(str1.equals(str2));
        System.out.println(str1.intern()==str2.intern());
    }
}
